package com.hopu.oa.service.impl.UserManageControllerImpl;

import com.hopu.oa.dao.UserManage.UserManageDao;
import com.hopu.oa.entity.dto.user.manage.UserManage;
import com.hopu.oa.entity.user.AoaPosition;
import com.hopu.oa.entity.user.AoaUser;
import com.hopu.oa.service.UserManageService.UserManageService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserManageServiceImp implements UserManageService {

    @Autowired
    private UserManageDao userManageDao;


    /*
     @Description : 根据当前用户  角色/部门  查询所用员工
     @Date   :  2021/11/15
     @Param  : [roleId, deptId]
     @return : java.util.List<com.hopu.oa.entity.dto.user.manage.UserManage>
    */
    @Override
    public List<UserManage> queryStaffByUserRoleOrDept(Integer roleId, Integer deptId, int index, int size, String name) {
        return userManageDao.queryStaffByUserRoleOrDept(roleId, deptId, index, size, name);
    }


    /*
      @Description : 计数
      @Date   :  2021/11/15
      @Param  : [roleId, deptId]
      @return : int
     */
    @Override
    public int queryStaffCount(Integer roleId, Integer deptId, String name) {
        return userManageDao.queryStaffCount(roleId, deptId, name);
    }


    /*
      @Description : 根据用户id删除用户
      @Date   :  2021/11/15
      @Param  : [userId]
      @return : boolean
     */
    @Override
    public boolean userManage_deleteUserById(int userId) {
        return userManageDao.userManage_deleteUserById(userId) == 1;
    }


    /*
      @Description :查询部门
      @Date   :  2021/11/15
      @Param  : []
      @return : java.util.List<java.util.Map<java.lang.String,java.lang.String>>
     */
    @Override
    public List<Map<String, String>> queryDeptIdAndDeptName(Integer roleId, Integer deptId) {
        return userManageDao.queryDeptIdAndDeptName(roleId, deptId);
    }


    /*
      @Description : 查询职位
      @Date   :  2021/11/15
      @Param  : [id]
      @return : java.util.List<com.hopu.oa.entity.user.AoaPosition>
     */
    @Override
    public List<AoaPosition> queryPositionIdAndPositionName(Integer id) {
        return userManageDao.queryPositionIdAndPositionName(id);
    }


    /*
      @Description : 查询角色
      @Date   :  2021/11/15
      @Param  : [roleId]
      @return : java.util.List<java.util.Map<java.lang.String,java.lang.String>>
     */
    @Override
    public List<Map<String, String>> queryRoleByUserId(Integer roleId) {
        return userManageDao.queryRoleByUserId(roleId);
    }

    @Override
    public boolean insertUser(UserManage user) {
        return userManageDao.insertUser(user) == 1;
    }


    /*
      @Description : 查询被修改的用户
      @Date   :  2021/11/16
      @Param  : [userid]
      @return : com.hopu.oa.entity.user.AoaUser
     */
    @Override
    public AoaUser queryUpdateUserById(String userid) {
        return userManageDao.queryUpdateUserById(userid);
    }

    @Override
    public boolean updateUserByUser(UserManage user) {
        return userManageDao.updateUserByUser(user) > 0;
    }


}
